home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Applications / ARTAbrot 1.21 / Main_ARTAbrot.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-12-08  |  23.7 KB  |  683 lines  |  [TEXT/MPS ]

  1. /* Main_ARTAbrot */
  2.  
  3. /* Program name:  Main_ARTAbrot   
  4.  Function:  This is the main module for this program.  
  5. History: 8/18/93 Original by George Warner
  6.    */
  7.  
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10.  
  11. #include "ComUtil_ARTAbrot.h"    /* Common */
  12.  
  13. #include "AB_Alert.h"    /* Alert */
  14. #include "About_ARTAbrot.h"    /* Modeless Dialog */
  15. #include "BrotCode.h"
  16. #include "Enter_Coordinates.h"    /* Modeless Dialog */
  17. #include "ARTAbrot.h"    /* Window */
  18. #include "Menu_ARTAbrot.h"    /* Menus */
  19.  
  20. #define gestaltRealtimeMgrAttr 'rtmr'
  21. enum  {
  22.     gestaltRealtimeMgrPresent   = 0
  23. };
  24.  
  25. Boolean        DoIt;                                /* Flag saying an event is ready */
  26. short        code;                                /* Determine event type */
  27. WindowPtr    whichWindow;                        /* See which window for event */
  28. long        mResult;                            /* Menu list and item selected values */
  29. short        theMenu,theItem;                    /* Menu list and item selected */
  30. Boolean        Is_A_Dialog;                        /* Flag for modless dialogs */
  31. short        charCode, itemHit;                    /* For modeless dialogs*/
  32. char        ch;                                    /* Key pressed in Ascii */
  33. Boolean        DoTheModelessEvent, CmdDown;        /* For modeless dialogs*/
  34. WindowPeek    thePeeked;                            /* For modeless dialogs*/
  35.  
  36. extern int processing_brot;
  37.  
  38. /* Handle key strokes */
  39. static void DoKeyEvent(void);
  40.  
  41. /* Handle a diskette inserted */
  42. static void DoDiskEvent(void);
  43.  
  44. /* Handle a window being resized */
  45. static void DoGrow(WindowPtr whichWindow);
  46.  
  47. /* Handle a window being dragged */
  48. static void DoDrag(WindowPtr whichWindow);
  49.  
  50. /* Handle a window goaway box */
  51. static void DoGoAway(WindowPtr whichWindow);
  52.  
  53. /* Handle an update to the window */
  54. static void DoUpdate(void);
  55.  
  56.  
  57. /* MAIN entry point */
  58. void main(void);
  59.  
  60. /* Handle the OS event */
  61. void DoOSEvent(EventRecord *myEvent);
  62.  
  63.  
  64. Boolean HasARTA(void)
  65. {
  66. OSErr error;
  67. long response;
  68.  
  69.     error = Gestalt(gestaltRealtimeMgrAttr, &response);
  70.     if (error)
  71.         return(0);
  72.     if (response & (1 << gestaltRealtimeMgrPresent))
  73.         return(1);
  74.     else
  75.         return(0);
  76. }
  77.  
  78. /* Routine: DoOSEvent */
  79. /* Purpose: Handle DoOSEvents */
  80.  
  81. void DoOSEvent(EventRecord *myEvent)
  82. {
  83.  
  84. if (((myEvent->message & osEvtMessageMask) >> 24) == suspendResumeMessage)/*  See which  */
  85.     {
  86.     if ((myEvent->message & resumeFlag) == 0)        /* Suspend */
  87.         {
  88.         InTheForeground = FALSE;
  89.         }
  90.     else
  91.         {
  92.         InTheForeground = TRUE;
  93.         }                                        /* End of IF */
  94.     }                                            /* End of IF */
  95. }
  96.  
  97. /* ======================================================= */
  98.  
  99. /* ======================================================= */
  100.  
  101. /* Routine: WNEIsImplemented */
  102. /* Purpose: See if the MultiFinder trap, WaitNextEvent, is available */
  103.  
  104. Boolean IsWNEIsImplemented()                /* See if WaitNextEvent is available */
  105. {
  106. #define    WNETrapNumber    0xA860                /* The expected trap number */
  107. #define    kGestaltTrapID    0xA1AD                /* The expected trap number */
  108.  
  109. SysEnvRec    theWorld;                        /* Environment record */
  110. OSErr    discardError;                        /* Error code returned */
  111. Boolean    theWNEIsImplemented;                /* Value to return */
  112. long    result;                                /* Value returned */
  113.  
  114.     Black_ForeColor.red = 0x0000;  Black_ForeColor.green = 0x0000;    Black_ForeColor.blue = 0x0000;  /* Get black color */
  115.     White_BackColor.red = 0xFFFF;  White_BackColor.green = 0xFFFF;  White_BackColor.blue = 0xFFFF;  /* Get white color */
  116.  
  117.     HasColorQD = FALSE;                        /* Init to no color QuickDraw */
  118.     HasFPU = FALSE;                            /* Init to no floating point chip */
  119.     HasAppleEvents = FALSE;                    /* Whether AppleEvents are available */
  120.     HasAliasMgr = FALSE;                    /* Whether AliasMgr is available */
  121.     HasEditionMgr = FALSE;                    /* Whether EditionMgr is available */
  122.     HasGestalt = FALSE;                        /* Whether Gestalt is available */
  123.     HasNewStdFile = FALSE;                    /* Whether HasNewStdFile is available */
  124.     HasPPCToolbox = FALSE;                    /* Whether PPCToolbox is available */
  125.     Has32BitQuickDraw = FALSE;                /* Whether 32Bit QuickDraw is available */
  126.     InTheForeground = TRUE;                    /* Init to a foreground app */
  127.     discardError = SysEnvirons(1, &theWorld);    /* Check how old this system is */
  128.     if (theWorld.machineType < 0) {            /* Negative means really old */
  129.         theWNEIsImplemented = FALSE;        /* Really old ROMs, no WNE possible */
  130.     }
  131.     else {
  132.         theWNEIsImplemented = CheckTrapAvailable(WNETrapNumber, ToolTrap);/* See if trap is there */
  133.         HasColorQD = theWorld.hasColorQD;    /* Flag for Color QuickDraw being available */
  134.         HasFPU = theWorld.hasFPU;            /* Flag for Floating Point Math Chip being available */
  135.         HasGestalt = CheckTrapAvailable(kGestaltTrapID, ToolTrap);    /* Whether Gestalt is available */
  136.         if (HasGestalt) {                    /* Do if Gestalt is available */
  137.             discardError = Gestalt(gestaltAliasMgrAttr,&result);
  138.             if ((discardError == 0) && ((result & (0x00000001 << gestaltAliasMgrPresent)) != 0))
  139.                 HasAliasMgr = TRUE;
  140.  
  141.             discardError = Gestalt(gestaltEditionMgrAttr,&result);
  142.             if ((discardError == 0) && ((result & (0x00000001 << gestaltEditionMgrPresent)) != 0))
  143.                 HasEditionMgr = TRUE;
  144.  
  145.             discardError = Gestalt(gestaltAppleEventsAttr,&result);
  146.             if ((discardError == 0) && ((result & (0x00000001 << gestaltAppleEventsPresent)) != 0))
  147.                 HasAppleEvents = TRUE;
  148.  
  149.             discardError = Gestalt(gestaltPPCToolboxAttr,&result);
  150.             if ((discardError == 0) && ((result & (0x00000001 << gestaltPPCToolboxPresent)) != 0))
  151.                 HasPPCToolbox = TRUE;
  152.  
  153.             discardError = Gestalt(gestaltQuickdrawVersion,&result);
  154.             if ((discardError == 0) && ((result & gestalt32BitQD) != 0))
  155.                 Has32BitQuickDraw = TRUE;
  156.  
  157.             discardError = Gestalt(gestaltStandardFileAttr,&result);
  158.             if ((discardError == 0) && ((result & (0x00000001 << gestaltStandardFile58)) != 0))
  159.                 HasNewStdFile = TRUE;
  160.         }
  161.     }
  162.     return(theWNEIsImplemented);
  163. }
  164.  
  165. /* ======================================================= */
  166.  
  167. /* Routine: Handle_User_Event */
  168. /* Purpose: Check for user events */
  169.  
  170. void Handle_User_Event()                            /* Check for user events */
  171. {
  172. UserEventRec    TheUserEvent;                        /* The user event */
  173.  
  174. GetUserEvent(&TheUserEvent);                        /* Check for any user events */
  175. if (TheUserEvent.ID != UserEvent_None)                /* Only do if we have any */
  176.     {
  177.  
  178.     switch (TheUserEvent.ID)                        /* Key off the Event ID */
  179.         {
  180.         case UserEvent_Open_Window:             /* Open a Window or Modeless dialog */
  181.             switch (TheUserEvent.ID2)                /* Do the appropiate window */
  182.                 {
  183.                 case Res_W_ARTAbrot: 
  184.                     Open_ARTAbrot();        /* Open this window */
  185.                     break;
  186.                 case Res_MD_About_ARTAbrot:
  187.                     Open_About_ARTAbrot();/* Open this modeless dialog */
  188.                     break;
  189.                 case Res_MD_Enter_Coordinat:
  190.                     Open_Enter_Coordinat();/* Open this modeless dialog */
  191.                     break;
  192.                 default:                        /* Handle others */
  193.                     break;
  194.                 }                                /* End of the switch */
  195.             break;
  196.  
  197.         case UserEvent_Close_Window:             /* Close a Window or Modeless dialog */
  198.             switch (TheUserEvent.ID2) {            /* Do the appropiate window */
  199.                 case Res_W_ARTAbrot:
  200.                     Close_ARTAbrot(WPtr_ARTAbrot);/* Close this window */
  201.                     break;
  202.                 case Res_MD_About_ARTAbrot:
  203.                     Close_About_ARTAbrot(WPtr_About_ARTAbrot);/* Close this modeless dialog */
  204.                     break;
  205.                 case Res_MD_Enter_Coordinat:
  206.                     Close_Enter_Coordinat(WPtr_Enter_Coordinat);/* Close this modeless dialog */
  207.                     break;
  208.                 default:                        /* Handle others */
  209.                     break;
  210.                 }                                /* End of the switch */
  211.  
  212.             break;
  213.         default:                                /* Not standard, must be program specific */
  214.             break;
  215.         }                                        /* End of switch */
  216.     }                                            /* End of IF */
  217. }
  218.  
  219. /* ======================================================= */
  220.  
  221. /* Routine: DoKeyEvent */
  222. /* Purpose: Handle a key pressed */
  223.  
  224. static void DoKeyEvent()                            /* Handle key presses */
  225. {
  226. short    charCode;                                    /* Key code */
  227. char    ch;                                        /* Key pressed in Ascii */
  228. long    mResult;                                    /* Menu list and item, if a command key */
  229. short    theMenu,theItem;                            /* Menu list and item, if command key */
  230.  
  231.     charCode = myEvent.message & charCodeMask;        /* Get the character */
  232.     ch = (char)charCode;                            /* Change it to ASCII */
  233.     
  234.     if ((myEvent.modifiers & cmdKey) != 0) {        /* See if Command key is down */
  235.         mResult = MenuKey(ch);                        /* See if a menu selection */
  236.         theMenu = HiWord(mResult);                    /* Get the menu list number */
  237.         theItem = LoWord(mResult);                    /* Get the menu item number */
  238.         if (theMenu != 0)                            /* See if a list was selected */
  239.             Handle_My_Menu(theMenu, theItem);        /* Do the menu selection */
  240.     
  241.         if (((ch == 'x') || (ch == 'X')) && (theInput != NIL))/* See if a standard Cut */
  242.             TECut(theInput);                        /* Handle a Cut in a TE area */
  243.         if (((ch == 'c') || (ch == 'C')) && (theInput != NIL))/* See if a standard Copy */
  244.             TECopy(theInput);                        /* Handle a Copy in a TE area */
  245.         if (((ch == 'v')  ||  (ch == 'V')) && (theInput != NIL))/* See if a standard Paste */
  246.             TEPaste(theInput);                        /* Handle a Paste in a TE area */
  247.         if ((ch = '.') && (processing_brot)) {
  248.             finish_brot();
  249.         }
  250.     }
  251.     else if (theInput != NIL)
  252.         TEKey(ch,theInput);                        /* Place the normal key stroke */
  253.  
  254. }
  255.  
  256. /* ======================================================= */
  257.  
  258. /* Routine: DoDiskEvent */
  259. /* Purpose: Handle a diskette inserted */
  260.  
  261. static void DoDiskEvent()                            /* Handle disk inserted */
  262. {
  263. short    theError;                                    /* Error returned from mount */
  264.  
  265. if (HiWord(myEvent.message) != noErr)                /* See if a diskette mount error */
  266.     {
  267.     myEvent.where.h = ((qd.screenBits.bounds.right - qd.screenBits.bounds.left) / 2) - (304 / 2);/* Center horz */
  268.     myEvent.where.v = ((qd.screenBits.bounds.bottom - qd.screenBits.bounds.top) / 3) - (104 / 2);/* Top 3ed vertically */
  269.     InitCursor();                                    /* Make sure it has an arrow cursor */
  270.     theError = DIBadMount(myEvent.where, myEvent.message);/* Let the OS handle the diskette */
  271.     }                                            /* End of IF */
  272.  
  273. }
  274.  
  275. /* ======================================================= */
  276.  
  277. /* Routine: DoGrow */
  278. /* Purpose: Handle a window resize */
  279.  
  280. static void DoGrow(WindowPtr whichWindow)
  281. {
  282. Rect    OldRect;                                    /* Window rect before the grow */
  283. Point    myPt;                                        /* Point for tracking grow box */
  284. Rect    GrowRect;                                    /* Set the grow bounds */
  285. long    mResult;                                    /* Result from the grow */
  286. long    theRefCon;                                    /* Refcon with layer masked off */
  287.  
  288. if (!Doing_MovableModal)                            /* Select proper window */
  289.     {
  290.     if (whichWindow != nil)                        /* See if we have a legal window */
  291.         {
  292.         SetPort(whichWindow);                        /* Get ready to draw in this window */
  293.  
  294.         myPt = myEvent.where;                        /* Get mouse position */
  295.         GlobalToLocal(&myPt);                        /* Make it relative */
  296.  
  297.         OldRect = whichWindow->portRect;            /* Save the rect before resizing */
  298.  
  299.  
  300.         theRefCon = GetWRefCon(whichWindow);        /* Get the refcon */
  301.         switch (theRefCon) {                            /* Do the appropriate window */
  302.             case Res_W_ARTAbrot:
  303.                 /* Don't allow resize if we're running. */
  304.                 if (!processing_brot) {
  305. //                    SetRect(&GrowRect, 4, 4, (qd.screenBits.bounds.right - qd.screenBits.bounds.left)-4,  (qd.screenBits.bounds.bottom - qd.screenBits.bounds.top) - 4);/* l,t,r,b */
  306.                     SetRect(&GrowRect, 4, 4, (1280)-4,  (qd.screenBits.bounds.bottom - qd.screenBits.bounds.top) - 4);/* l,t,r,b */
  307.                     mResult = GrowWindow(whichWindow, myEvent.where, &GrowRect);/* Grow it */
  308.                     SizeWindow(whichWindow, LoWord(mResult), HiWord(mResult), true);/* Resize to result */
  309.                     Resized_ARTAbrot(whichWindow);    /* Resized this window */
  310.                 }
  311.                 break;
  312.             default:                            /* allow other buttons, trap for debug */
  313.                 SetRect(&GrowRect, 4, 4, (qd.screenBits.bounds.right - qd.screenBits.bounds.left)-4,  (qd.screenBits.bounds.bottom - qd.screenBits.bounds.top) - 4);/* l,t,r,b */
  314.                 mResult = GrowWindow(whichWindow, myEvent.where, &GrowRect);/* Grow it */
  315.                 SizeWindow(whichWindow, LoWord(mResult), HiWord(mResult), true);/* Resize to result */
  316.                 break;
  317.         }
  318.  
  319.         SetPort(whichWindow);                        /* Get ready to draw in this window */
  320.  
  321.         myPt.h = whichWindow->portRect.right - whichWindow->portRect.left;/* Local right edge */
  322.         myPt.v = whichWindow->portRect.bottom - whichWindow->portRect.top;/* Local bottom edge */
  323.  
  324.         SetRect(&GrowRect, 0, OldRect.bottom - 15, OldRect.right + 15, OldRect.bottom + 15);/* Position for horz scrollbar area */
  325.         EraseRect(&GrowRect);                        /* Erase old area */
  326.         InvalRect(&GrowRect);                        /* Flag us to update it */
  327.  
  328.         SetRect(&GrowRect, OldRect.right - 15, 0, OldRect.right + 15, OldRect.bottom + 15);/* Position for vert scrollbar area */
  329.         EraseRect(&GrowRect);                        /* Erase old area */
  330.         InvalRect(&GrowRect);                        /* Flag us to update it */
  331.  
  332.         DrawGrowIcon(whichWindow);                    /* Draw the grow Icon again */
  333.         }                                        /* End of IF */
  334.     }                                            /* End of IF */
  335. }
  336.  
  337.  
  338.  
  339. /* Routine: DoDrag */
  340. /* Purpose: Drag a window around */
  341.  
  342. static void DoDrag(WindowPtr whichWindow)
  343. {
  344. Rect    OldRect;                            /* Window rect before the drag */
  345. Rect    tempRect;                            /* temporary rect */
  346. long    theRefCon;                            /* Refcon with layer masked off */
  347.  
  348.     if ((!Doing_MovableModal) || (Doing_MovableModal && (whichWindow == FrontWindow()))) {    /* See if OK to drag */
  349.         OldRect = whichWindow->portRect;    /* Save the rect before resizing */
  350.  
  351.         tempRect = qd.screenBits.bounds;    /* Get screen area,  l,t,r,b, drag area */
  352.         SetRect(&tempRect,tempRect.left+4,tempRect.top+4,tempRect.right-4,tempRect.bottom - 4);
  353.         DragWindow(whichWindow, myEvent.where, &tempRect);    /* Drag the window */
  354.  
  355.         theRefCon = GetWRefCon(whichWindow);    /* Get the refcon */
  356.         switch (theRefCon) {                /* Do the appropiate window */
  357.             case Res_W_ARTAbrot:
  358.                 Moved_ARTAbrot(whichWindow);    /* Moved this window */
  359.                 break;
  360.             case Res_MD_About_ARTAbrot:
  361.                 Moved_About_ARTAbrot(whichWindow);    /* Moved this modeless dialog */
  362.                 break;
  363.             case Res_MD_Enter_Coordinat:
  364.                 Moved_Enter_Coordinat(whichWindow);    /* Moved this modeless dialog */
  365.                 break;
  366.             default:                        /* allow other buttons, trap for debug */
  367.                 break;    
  368.         }    
  369.     }    
  370. }
  371.  
  372.  
  373.  
  374. /* Routine: DoGoAway */
  375. /* Purpose: Close a window */
  376.  
  377. static void DoGoAway(WindowPtr whichWindow)
  378. {
  379. long    theRefCon;                                    /* Refcon with layer masked off */
  380.  
  381.     if (!Doing_MovableModal) {                            /* Select proper window */
  382.         if (TrackGoAway(whichWindow,myEvent.where)) {    /* See if mouse released in GoAway box */
  383.             theRefCon = GetWRefCon(whichWindow);        /* Get the refcon */
  384.             switch (theRefCon) {                            /* Do the appropiate window */
  385.                 case Res_W_ARTAbrot:
  386.                     Close_ARTAbrot(whichWindow);        /* Close this window */
  387.                     break;
  388.                 case Res_MD_About_ARTAbrot:
  389.                     Close_About_ARTAbrot(whichWindow);/* Close this modeless dialog */
  390.                     break;
  391.                 case Res_MD_Enter_Coordinat:
  392.                     Close_Enter_Coordinat(whichWindow);/* Close this modeless dialog */
  393.                     break;
  394.                 default:                            /* allow other buttons, trap for debug */
  395.                     break;    
  396.             }    
  397.         }    
  398.     }    
  399. }
  400.  
  401.  
  402.  
  403. /* Routine: DoInContent */
  404. /* Purpose: Pressed in the content area */
  405.  
  406. static void DoInContent(WindowPtr whichWindow,EventRecord *myEvent)
  407. {
  408. long    theRefCon;                            /* Refcon with layer masked off */
  409.  
  410.     if (!Doing_MovableModal) {                /* Select proper window */
  411.         if (whichWindow != FrontWindow()) {    /* See if already selected or not, in front if selected */
  412.             SelectWindow(whichWindow);        /* Select this window to make it active */
  413.         }
  414.         else {
  415.             SetPort(whichWindow);            /* Get ready to draw in this window */
  416.             theRefCon = GetWRefCon(whichWindow);    /* Get the refcon */
  417.             switch (theRefCon) {            /* Do the appropiate window */
  418.                 case Res_W_ARTAbrot:
  419.                     Do_ARTAbrot(myEvent);    /* Handle this window */
  420.                     break;
  421.                 default:                    /* allow other buttons, trap for debug */
  422.                     break;
  423.             }
  424.         }
  425.     }
  426. }
  427.  
  428.  
  429.  
  430. /* Routine: DoUpdate */
  431. /* Purpose: Got an update event */
  432.  
  433. static void DoUpdate()
  434. {
  435. WindowPtr    whichWindow;                    /* See which window for event */
  436. long    theRefCon;                            /* Refcon with layer masked off */
  437.  
  438.     whichWindow = (WindowPtr)myEvent.message;    /* Get the window the update is for */
  439.  
  440.     BeginUpdate(whichWindow);                /* Set the clipping to the update area */
  441.     theRefCon = GetWRefCon(whichWindow);    /* Get the refcon */
  442.     switch (theRefCon) {                    /* Do the appropiate window */
  443.         case Res_W_ARTAbrot:
  444.             Update_ARTAbrot(whichWindow);    /* Update this window */
  445.             break;
  446.         default:                            /* allow other buttons, trap for debug */
  447.             break;
  448.     }
  449.     EndUpdate(whichWindow);                    /* Return to normal clipping area */
  450. }
  451.  
  452.  
  453.  
  454. /* Routine: DoActivate */
  455. /* Purpose: Got an activate or deactivate event */
  456.  
  457. void DoActivate()
  458. {
  459. WindowPtr    whichWindow;                /* See which window for event */
  460. Boolean    Do_An_Activate;                    /* Flag to pass */
  461. long    theRefCon;                        /* Refcon with layer masked off */
  462.  
  463.     whichWindow = (WindowPtr)myEvent.message;    /* Get the window the update is for */
  464.  
  465.     Do_An_Activate =  ((myEvent.modifiers & 0x0001) != 0);    /* Make sure it is Activate and not DeActivate */
  466.     theRefCon = GetWRefCon(whichWindow);    /* Get the refcon */
  467.     switch (theRefCon) {                /* Do the appropiate window */
  468.         case Res_W_ARTAbrot:
  469.             Activate_ARTAbrot(whichWindow,Do_An_Activate);    /* Activate or deactivate this window */
  470.             break;
  471.         default:                        /* allow other buttons, trap for debug */
  472.             break;
  473.     }
  474. }
  475.  
  476.  
  477.  
  478. void main()
  479. {
  480. char tmp_string[256];
  481.  
  482.     MoreMasters();                        /* This reserves space for more handles */
  483.     MaxApplZone();                        /* Give us room for memory allocation */
  484.     InitGraf((Ptr) &qd.thePort);        /* Quickdraw Init */
  485.     InitFonts();                        /* Font manager init */
  486.     InitWindows();                        /* Window manager init */
  487.     InitMenus();                        /* Menu manager init */
  488.     TEInit();                            /* Text edit init */
  489.     InitDialogs(nil);                    /* Dialog manager */
  490.  
  491.     FlushEvents(everyEvent , 0);        /* Clear out all events */
  492.     InitCursor();                        /* Make an arrow cursor */
  493.  
  494.     doneFlag = FALSE;                    /* Do not exit program yet */
  495.  
  496.     Init_My_Menus();                    /* Initialize menu bar */
  497.  
  498.     theInput = nil;                        /* Init to no text edit selection active */
  499.  
  500.     SleepValue = 0;                        /* Set sleep value */
  501.     WNE = IsWNEIsImplemented();            /* See if WaitNextEvent is available */
  502.  
  503.     /* We need certain minimum conditions.  We'll check here. */
  504.     if (!HasGestalt) {
  505.         sprintf(tmp_string, "Sorry, Gestalt required for this program.");
  506.         AB_Alert(tmp_string);
  507.         doneFlag = TRUE;                /* Exit program. */
  508.     }
  509.  
  510.     if (doneFlag == FALSE) {
  511.         if (!HasColorQD) {
  512.             sprintf(tmp_string, "Sorry, Color Quickdraw required for this program.");
  513.             AB_Alert(tmp_string);
  514.             doneFlag = TRUE;            /* Exit program. */
  515.         }
  516.     }
  517.  
  518.     if (doneFlag == FALSE) {
  519.         if (!HasARTA()) {
  520.             sprintf(tmp_string, "Sorry, DSP3210 ARTA required for this program.");
  521.             AB_Alert(tmp_string);
  522.             doneFlag = TRUE;            /* Exit program. */
  523.         }
  524.     }
  525.  
  526.     UserEventList = nil;                /* No user events yet */
  527.  
  528.     cursorRgn = NewRgn();                /* Cursor region for WaitNextEvent */
  529.  
  530.     Init_ARTAbrot();                    /* Initialize the window routines */
  531.     Init_About_ARTAbrot();                /* Initialize the modeless dialog routines */
  532.     I_A_Alert();                        /* Initialize the alert globals */
  533.     Init_Enter_Coordinat();                /* Initialize the modeless dialog routines */
  534.     Doing_MovableModal = false;            /* Not currently doing a movable modal */
  535.  
  536.     if (doneFlag == FALSE) {
  537.         new_coordinates=TRUE;
  538.     
  539.         /* Open a Window */
  540.         Add_UserEvent(UserEvent_Open_Window,Res_W_ARTAbrot,0,0,nil);
  541.     }
  542.  
  543.     do {
  544.         if (processing_brot)
  545.             continue_brot();            /* See if we can get a line of Mandelbrot. */
  546.         Handle_User_Event();            /* Check for user events */
  547.         if (theInput != NIL) {            /* See if a TE is active */
  548.             TEIdle(theInput);            /* Blink the cursor if everything is ok */
  549.         }
  550.         if (WNE) {                        /* See if do the MultiFinder way */
  551.             DoIt = WaitNextEvent(everyEvent, &myEvent, SleepValue, cursorRgn);/* Wait for an event */
  552.         }
  553.         else {
  554.             SystemTask();                /* For support of desk accessories */
  555.             DoIt = GetNextEvent(everyEvent, &myEvent);/* See if an event is ready */
  556.         }
  557.  
  558.         if (DoIt) {                        /* If event then... */
  559.             Is_A_Dialog = IsDialogEvent(&myEvent);    /* See if a modeless dialog event */
  560.             if (Is_A_Dialog == TRUE) {                /* Handle a dialog event */
  561.                 if (myEvent.what == updateEvt) {    /* Handle the update of a Modeless Dialog */
  562.                     whichWindow = (WindowPtr)myEvent.message; /* Get the window the update is for */
  563.                     BeginUpdate(whichWindow);        /* Set update clipping area */
  564.                     Update_About_ARTAbrot(whichWindow);    /* Update the modeless dialog */
  565.                     Update_Enter_Coordinat(whichWindow);/* Update the modeless dialog */
  566.                     EndUpdate(whichWindow);            /* Return to normal clipping area */
  567.                 }
  568.                 else {
  569.                     DoTheModelessEvent = TRUE;        /* Go ahead and do it so far */
  570.  
  571.                     if (myEvent.what == keyDown) {     /* Check the key down, for a command key event */
  572.                         CmdDown = ((myEvent.modifiers / cmdKey) & 1);/* Get the command key state */
  573.                         charCode = myEvent.message & charCodeMask;/* Get the character */
  574.                         ch = (char)charCode;        /* Change it to ASCII */
  575.  
  576.                         if ((charCode == 13) || (charCode == 0x03))/* CR or Enter */
  577.                             DoTheModelessEvent = TRUE;/* Handle the default selection */
  578.  
  579.                         if (CmdDown != 0) {            /* Handle if the command key was down */
  580.                             mResult = MenuKey(ch);    /* See if a menu selection */
  581.                             theMenu = HiWord(mResult);    /* Get the menu list number */
  582.                             theItem = LoWord(mResult);    /* Get the menu item number */
  583.                             if (theMenu != 0)          /* See if a list was selected */
  584.                                 Handle_My_Menu(theMenu, theItem); /* Do the menu selection */
  585.  
  586.                             whichWindow = FrontWindow(); /* Get the front window */
  587.                             if ((ch == 'x') || (ch == 'X'))    /* Handle a CUT */
  588.                                 DlgCut(whichWindow);/* Do the dialog cut */
  589.                             if ((ch == 'c') || (ch == 'C'))    /* Handle a COPY */
  590.                                 DlgCopy(whichWindow);/* Do the dialog copy */
  591.                             if ((ch == 'v') || (ch == 'V'))    /* Handle a PASTE */
  592.                                 DlgPaste(whichWindow);    /* Do the dialog paste */
  593.  
  594.                             DoTheModelessEvent = FALSE;/* We handled the command key */
  595.                         }
  596.                     }
  597.  
  598.                     if (DoTheModelessEvent == TRUE) {     /* Do we handle it? */
  599.                         if ((DialogSelect(&myEvent, &whichWindow, &itemHit)) || (myEvent.what == mouseDown) || (myEvent.what == keyDown)) { /* Ck if do it */
  600.                             Do_About_ARTAbrot(&myEvent,whichWindow,itemHit);    /* Handle the Modeless Dialog */
  601.                             Do_Enter_Coordinat(&myEvent,whichWindow,itemHit);    /* Handle the Modeless Dialog */
  602.                         }
  603.                     }
  604.                 }
  605.             }
  606.             else {
  607.                 switch (myEvent.what) {        /* Decide type of event */
  608.                     case mouseDown :        /* Mouse button pressed */
  609.                         code = FindWindow(myEvent.where, &whichWindow);/* Get which window the event happened in */
  610.  
  611.                         switch (code) {        /* Decide type of event again */
  612.                             case inMenuBar:    /* In the menubar */
  613.                                 mResult = MenuSelect(myEvent.where);    /* Do menu selection */
  614.                                 theMenu = HiWord(mResult);    /* Get the menu list number */
  615.                                 theItem = LoWord(mResult);    /* Get the menu list item number */
  616.                                 Handle_My_Menu( theMenu, theItem);    /* Handle the menu */
  617.                                 break;
  618.  
  619.                             case inDrag:    /* In window drag area */
  620.                                 DoDrag(whichWindow);    /* Go drag the window */
  621.                                 break;
  622.  
  623.                             case inGrow:    /* In window grow area */
  624.                                 DoGrow(whichWindow);    /* Handle the growing */
  625.                                 break;
  626.  
  627.                             case inGoAway:    /* In window goaway area */
  628.                                 DoGoAway(whichWindow);    /* Handle the goaway button */
  629.                                 break;
  630.  
  631.                             case inContent:    /* In window  contents */
  632.                                 DoInContent(whichWindow,&myEvent);    /* Handle the hit inside a window */
  633.                                 break;
  634.  
  635.                             case inSysWindow:    /* See if a DA selectio */
  636.                                 SystemClick(&myEvent, whichWindow);    /* Let other programs in */
  637.                                 break;
  638.  
  639.                             default:        /* Handle others */
  640.                                 break;
  641.                         }
  642.                         break;                /* End of MouseDown */
  643.  
  644.                     case keyDown:            /* Handle key inputs */
  645.                     case autoKey:            /* and auto repeats */
  646.                         DoKeyEvent();        /* Get the key and handle it */
  647.                         break;
  648.  
  649.                     case updateEvt:            /* Update event for a window */
  650.                         DoUpdate();            /* Handle the update */
  651.                         break;
  652.  
  653.                     case diskEvt:            /* Disk inserted event */
  654.                         DoDiskEvent();        /* Handle a disk event */
  655.                         break;
  656.  
  657.                     case activateEvt:        /* Window activated event */
  658.                         DoActivate();        /* Handle the activation */
  659.                         break;
  660.  
  661.                     case osEvt:                /* OS event */
  662.                         DoOSEvent(&myEvent);    /* Handle the activation */
  663.                         break;                    /* End of osEvt */
  664.  
  665.                     default:                /* Used for debugging, to see what other events are coming in */
  666.                         break;
  667.                 }
  668.             }
  669.         }
  670.         else {
  671.             whichWindow = FrontWindow();    /* Get the current front window */
  672.             if (whichWindow != NIL) {        /* See if we have a window */
  673.                 thePeeked = (WindowPeek)whichWindow;    /* Peek inside, look for dialog */
  674.                 if (thePeeked->windowKind == dialogKind) {    /* DialogSelect will crash if no dialogs */
  675.                     if (DialogSelect(&myEvent, &whichWindow, &itemHit)) { /* Blink cursor in modeless TEs */
  676.                     }
  677.                 }
  678.             }
  679.         }
  680.     }
  681.     while (doneFlag == FALSE);                /* End of the event loop */
  682. }                                            /* end of main */
  683.